﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Maticsoft.Web.Customers
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int CustomerId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(CustomerId);
				}
			}
		}
			
	private void ShowInfo(int CustomerId)
	{
		Maticsoft.BLL.Customers bll=new Maticsoft.BLL.Customers();
		Maticsoft.Model.Customers model=bll.GetModel(CustomerId);
		this.lblCustomerId.Text=model.CustomerId.ToString();
		this.txtCustomerName.Text=model.CustomerName;
		this.txtPhone.Text=model.Phone;
		this.txtEmail.Text=model.Email;
		this.txtAddress.Text=model.Address;
		this.txtBalance.Text=model.Balance.ToString();
		this.txtCreateAt.Text=model.CreateAt.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtCustomerName.Text.Trim().Length==0)
			{
				strErr+="客户名称不能为空！\\n";	
			}
			if(this.txtPhone.Text.Trim().Length==0)
			{
				strErr+="手机不能为空！\\n";	
			}
			if(this.txtEmail.Text.Trim().Length==0)
			{
				strErr+="邮箱不能为空！\\n";	
			}
			if(this.txtAddress.Text.Trim().Length==0)
			{
				strErr+="地址不能为空！\\n";	
			}
			if(!PageValidate.IsDecimal(txtBalance.Text))
			{
				strErr+="账号余额格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCreateAt.Text))
			{
				strErr+="创建时间格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int CustomerId=int.Parse(this.lblCustomerId.Text);
			string CustomerName=this.txtCustomerName.Text;
			string Phone=this.txtPhone.Text;
			string Email=this.txtEmail.Text;
			string Address=this.txtAddress.Text;
			decimal Balance=decimal.Parse(this.txtBalance.Text);
			DateTime CreateAt=DateTime.Parse(this.txtCreateAt.Text);


			Maticsoft.Model.Customers model=new Maticsoft.Model.Customers();
			model.CustomerId=CustomerId;
			model.CustomerName=CustomerName;
			model.Phone=Phone;
			model.Email=Email;
			model.Address=Address;
			model.Balance=Balance;
			model.CreateAt=CreateAt;

			Maticsoft.BLL.Customers bll=new Maticsoft.BLL.Customers();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
